var prefixUrl = "http://localhost:8080/plaque/";
var imageUrl = "http://localhost:8080/plaque/images/";
var userId = getCookie("factoryCookie",1);
var state = getCookie("factoryCookie",2);

function getNumberList(data) {
    var total = data.data.total;
    var remainder = total%20;
    var allNumber = 0;
    if(remainder > 0){
        allNumber = parseInt(total/20) + 1;
    }else{
        allNumber = parseInt(total/20);
    }
    var number = 1;
    var numberHtml = '<li><a onclick=queryScheduleList('+ "0" +')>«</a></li>';
    for(var i=0; i<allNumber; i++){
        var id = "query-" + i;
        if(i == 0){
            numberHtml = numberHtml
                +'<li id="'+ id + '" name="queryList" class="active"><a onclick=queryScheduleList('+ i +')>' + number + '</a></li>';
        }else{
            numberHtml = numberHtml
                +'<li id="'+ id + '" name="queryList"><a onclick=queryScheduleList('+ i +')>' + number + '</a></li>';
        }
        number++;
    }
    numberHtml = numberHtml + '<li><a onclick=queryScheduleList('+ (allNumber-1) +')>»</a></li>';
    $("#queryList").html(numberHtml);
}

function modalDisplay(){
    $(".modal-backdrop").css("display","none");
    $(".modal").css("display","none");
}


function saveLunBoPic(formData){
    $.ajax({
        type: "POST",
        url: prefixUrl + "image/upload",
        data: formData,
        async: false,
        cache: false,
        contentType: false,
        processData: false,
        success: function (data) {
            console.log(data);
            lunboImgesUrl =  lunboImgesUrl + imageUrl + data  + "," ;
            console.log(lunboImgesUrl);
        },
        error: function(data) {
            alert("error:"+data.responseText);
        }
    });
}

init();

function init(){
    if(state == 1){
        $(".audit").hide();
    }else if(state == 2){
        $(".apply").hide();
    }
}

function getCookie(name,number){
    var strcookie = document.cookie;//获取cookie字符串
    var arrcookie = strcookie.split("; ");//分割
    //遍历匹配
    for ( var i = 0; i < arrcookie.length; i++) {
        var arr = arrcookie[i].split("=");
        if (arr[0] == name){
            if(arr[number].indexOf("\"") != -1){
                if(number == 1){
                    return arr[number].substring(1,arr[number].length);
                }else if(number == arr.length - 1){
                    return arr[number].substring(0,arr[number].length - 1);
                }
            }
            return arr[number];
        }
    }
    return "";
}

function goToLogin(data){
    if(data.code == "1001"){
        alert(data.msg);
        window.location.href = "login.html";
    }
}

function getPageImageList(detailList){
    var imgType = 1;
    var pageImgUrls = "";
    for(var i=0; i<detailList.length; i++){
        if(detailList[i].imgType == imgType){
            pageImgUrls = pageImgUrls + detailList[i].imgUrl + ",";
            imgType++;
        }
    }
    return pageImgUrls;
}

function getImageUrlList(list){
    var oneList = [];
    var twoList = [];
    var threeList = [];
    var fourList = [];
    var fiveList = [];
    var sixList = [];
    var sevenList = [];
    var eigthList = [];
    var nineList = [];
    var theList = [];
    var elevenList = [];
    var twelveList = [];
    for(var i=0; i<list.length; i++){
        var data = list[i];
        switch(data.imgType){
            case 1 : oneList.push(data); break;
            case 2 : twoList.push(data); break;
            case 3 : threeList.push(data); break;
            case 4 : fourList.push(data); break;
            case 5 : fiveList.push(data); break;
            case 6 : sixList.push(data); break;
            case 7 : sevenList.push(data); break;
            case 8 : eigthList.push(data); break;
            case 9 : nineList.push(data); break;
            case 10 : theList.push(data); break;
            case 11 : elevenList.push(data); break;
            case 12 : twelveList.push(data); break;
        }
    }
    imageUrlList[0] = oneList;
    imageUrlList[1] = twoList;
    imageUrlList[2] = threeList;
    imageUrlList[3] = fourList;
    imageUrlList[4] = fiveList;
    imageUrlList[5] = sixList;
    imageUrlList[6] = sevenList;
    imageUrlList[7] = eigthList;
    imageUrlList[8] = nineList;
    imageUrlList[9] = theList;
    imageUrlList[10] = elevenList;
    imageUrlList[11] = twelveList;
    console.log(imageUrlList);
}